﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;

namespace ProyectoCine.AreaPrivada
{
    public partial class Horarios : System.Web.UI.Page, IGrilla
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ViewState["Orden"] = "";
                cargarGrilla();
            }
        }

        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            string diaSemana = null;
            if (ddlDiaSemana.SelectedIndex != 0)
                diaSemana = ddlDiaSemana.SelectedValue;
            gvHorarios.DataSource = HorarioDAO.cargarGrillaByFiltro(diaSemana, ViewState["Orden"].ToString());
           gvHorarios.DataBind();

        }

        public void cargarGrilla()
        {
            gvHorarios.DataKeyNames = new string[] { "id_Horario" };
            gvHorarios.DataSource = HorarioDAO.cargarGrilla(ViewState["Orden"].ToString());
            gvHorarios.DataBind();
        }

        protected void gvHorarios_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["id_HorarioEdicion"] = gvHorarios.SelectedDataKey.Value;
            Response.Redirect("AltaHorario.aspx");
        }

        protected void gvHorarios_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvHorarios.PageIndex = e.NewPageIndex;
            cargarGrilla();
        }

        protected void gvHorarios_Sorting(object sender, GridViewSortEventArgs e)
        {
            ViewState["Orden"] = e.SortExpression;
            cargarGrilla();
        }
    }
}